﻿using System.Collections;
using System.Collections.Generic;
using System.Dynamic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    public float moveSpeed=12f; //子弹速度
    public GameObject expObj;   //爆炸粒子
    public Transform firePos;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    private void Awake()
    {
        //子弹产生后5s后子弹销毁
        Destroy(gameObject, 5f);
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
        //关闭忽略物理运算开关
        ObjectPool.objArray[0].GetComponent<Rigidbody>().isKinematic = true;
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(expObj!=null)
        {
            Instantiate(expObj,transform.position, Quaternion.identity);
        }
        //Destroy(gameObject);
        //回到出发点
        transform.position = firePos.position;
    }
}
